package com.example.controller;

import com.example.service.ChinaService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/chinaDatas")
@RequiredArgsConstructor
public class ChinaController {

    private final ChinaService chinaService;

    @GetMapping("/provinces")
    public Result<List<String>> getAllProvinces() {
        List<String> provinces = chinaService.getAllProvinces();
        return new Result<>(provinces, 1, "获取所有省成功");
    }
    
    @GetMapping("/citys")
    public Result<List<String>> getCitys(@RequestParam String province) {
        log.info(province);
        List<String> citys = chinaService.getAllCitys(province);
        return new Result<>(citys, 1, "获取所有市成功");
    }

    @GetMapping("districts")
    public Result<List<String>> getDistricts(@RequestParam String city) {
        List<String> districts = chinaService.getDistricts(city);
        return new Result<>(districts, 1, "获取所有区成功");
    }
}
